package service

import (
	"fmt"
	"github.com/jmoiron/sqlx"
)

type User struct {
	Name string `db:"name"`
	Age  int    `db:"age"`
}

var Db *sqlx.DB

func init() {
	database, err := sqlx.Open("mysql", "root:orcl@tcp(127.0.0.1:3306)/wj")
	if err != nil {
		fmt.Println("open mysql failed,", err)
		return
	}
	Db = database
}

func main() {
	for i := 0; i < 1000; i++ {
		r, err := Db.Exec("insert into user (name) values (?)", i)
		if err != nil {
			fmt.Println("insert failed,", err)
			return
		}
		id, err := r.LastInsertId()
		if err != nil {
			fmt.Println("get LastInsertId failed,", err)
		}
		fmt.Println("insert success, id=", id)
	}
}
